package huachenxing.mimi520.option.widgets
{
	import com.cambright.stack.components.layout.Element;
	import com.cambright.stack.components.layout.Fill;
	
	import flash.geom.Rectangle;
	
	import huachenxing.mimi520.option.commands.CloseWorkerWindowCommand;
	import huachenxing.mimi520.option.models.WorkerModel;
	import huachenxing.mimi520.skin.Input;
	import huachenxing.mimi520.skin.Text;
	
	public class WorkerWindowWidget extends WindowWidget
	{
		private var _retryInput:Input;
		private var _queryInput:Input;
		private var _answerInput:Input;
		
		override protected function invoke():void
		{
			super.invoke();
			
			var tipLabel:Text = new Text("网络情况不佳时适当加大以下各值");
			tipLabel.color = 0xFF0000;
			tipLabel.size = 12;
			
			var retryLabel:Text = new Text("网络请求重试次数 (n>2)");
			retryLabel.color = 0x707c89;
			
			_retryInput = new Input();
			_retryInput.textColor = 0x707c89;
			
			var queryLabel:Text = new Text("查询问题网络请求间隔(秒)(n>3)");
			queryLabel.color = 0x707c89;
			
			_queryInput = new Input();
			_queryInput.textColor = 0x707c89;
			
			var answerLabel:Text = new Text("回答处理请求间隔(秒)(n>3)");
			answerLabel.color = 0x707c89;
			
			_answerInput = new Input();
			_answerInput.textColor = 0x707c89;
			
			addElement(new Element(tipLabel, 2));
			addElement(new Element(retryLabel, 3));
			addElement(new Element(_retryInput, 4, Fill.HORIZONTAL));
			addElement(new Element(queryLabel, 5));
			addElement(new Element(_queryInput, 6, Fill.HORIZONTAL));
			addElement(new Element(answerLabel, 7));
			addElement(new Element(_answerInput, 8, Fill.HORIZONTAL));
		}
		
		override protected function get rect():Rectangle
		{
			return new Rectangle(Number.MIN_VALUE, Number.MIN_VALUE, 300, 280);
		}
		
		override protected function get title():String
		{
			return "账号设置";
		}
		
		override protected function get close():Class
		{
			return CloseWorkerWindowCommand;
		}
		
		override protected function enable():void
		{
			_retryInput.text = WorkerModel.retry.toString();
			_queryInput.text = WorkerModel.query.toString();
			_answerInput.text = WorkerModel.answer.toString();
			super.enable();
		}
		
		override protected function disable():void
		{
			super.disable();
			WorkerModel.retry = int(_retryInput.text);
			WorkerModel.query = int(_queryInput.text);
			WorkerModel.answer = int(_answerInput.text);
		}
	}
}